package com.appspot.showup_app.showup.tasks;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.appspot.showup_app.showup.AppConstants;
import com.appspot.showup_app.showup.ApplicationData;
import com.appspot.showup_app.showup.Showup;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;

/**
 * Created by Gal on 12/7/2014.
 */

public class DeleteAppointmentTask extends AsyncTask<Void, Void, Void> {

    private static final String LOG_TAG = "UpdateAppointmentTask";
    private static final String TAG = "Showup";
    private final Context mContext;
    public String mAppointmentId;

    public DeleteAppointmentTask(Context context, String appointmentId) {
        mContext =  context;
        mAppointmentId = appointmentId;
    }

    @Override
    protected Void doInBackground(Void... unused) {

        if (!AppConstants.checkGooglePlayServicesAvailable((Activity) mContext)) {
            return null;
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(mContext.getApplicationContext(), AppConstants.AUDIENCE);
        credential.setSelectedAccountName(ApplicationData.getInstance().emailAccount);
        Showup api = AppConstants.getApiServiceHandle(credential);

        try {
            return api.appointment().delete(mAppointmentId).execute();

        } catch (Exception e) {
            Log.e(LOG_TAG, "Exception during API call", e);
        }
        return null;
    }

}
